package com.briup.estore.controller;

import com.briup.estore.entity.BannerEntity;
import com.briup.estore.entity.CollectEntity;
import com.briup.estore.entity.ShopEntity;
import com.briup.estore.entity.UserEntity;
import com.briup.estore.entity.vo.CollectVO;
import com.briup.estore.service.BannerService;
import com.briup.estore.service.CollectService;
import com.briup.estore.service.ShopService;
import com.briup.estore.service.impl.BannerServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author adam
 * @date 2023/3/31
 */
@Controller
@Slf4j
public class SystemController {
    @Autowired
    private CollectService collectService;

    @GetMapping(value = {"/toIndex", "/"})
    public String toIndex(HttpServletRequest request) {
        HttpSession session = request.getSession();
        return "index";
    }

    @GetMapping("toLogin")
    public String toLogin() {
        return "login";
    }

    @GetMapping("toRegister")
    public String toRegister() {
        return "register";
    }

    @GetMapping("toCollect")
    public String toCollect(HttpSession session, Model model) {
        UserEntity user = (UserEntity) session.getAttribute("user");
        List<CollectVO> collects = collectService.findCollectByUser(user.getId());
        model.addAttribute("collects", collects);
        return "collect";
    }
}
